from pyecharts import Graph
import pickle
import jieba
from collections import Counter 
with open('content.ekl','rb') as f1:
    line = pickle.loads(f1.read())



#分词
seg_list = jieba.cut(line)  
c = Counter()  
for x in seg_list:  
	if len(x)>1 and x != '\r\n':  
		c[x] += 1  
print('常用词频度统计结果')  
nodes =[]
for (k,v) in c.most_common(100): 
	print(str(k) + ":" +  str(v))
	nodes.append({"name":str(k),"symbolSize":str(v)})

links = []
for i in nodes:
    for j in nodes:
        links.append({"source": i.get('name'), "target": j.get('name')})
graph = Graph("关系图-力引导布局示例")
graph.add("", nodes, links, repulsion=8000)
graph.render()

# from pyecharts import Graph

# nodes = [{"name": "结点1", "symbolSize": 10},
#          {"name": "结点2", "symbolSize": 20},
#          {"name": "结点3", "symbolSize": 30},
#          {"name": "结点4", "symbolSize": 40},
#          {"name": "结点5", "symbolSize": 50},
#          {"name": "结点6", "symbolSize": 40},
#          {"name": "结点7", "symbolSize": 30},
#          {"name": "结点8", "symbolSize": 20}]
# links = []
# for i in nodes:
#     for j in nodes:
#         links.append({"source": i.get('name'), "target": j.get('name')})
# graph = Graph("关系图-力引导布局示例")
# graph.add("", nodes, links, repulsion=8000)
# graph.render()